package com.ruoyi.web.controller.record;

import java.util.List;

import com.ruoyi.common.utils.ShiroUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.web.domain.ExecutionRecord;
import com.ruoyi.web.service.IExecutionRecordService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * recordController
 * 
 * @author ruoyi
 * @date 2023-10-19
 */
@Controller
@RequestMapping("/execution/record")
public class ExecutionRecordController extends BaseController
{
    private String prefix = "execution/record";

    @Autowired
    private IExecutionRecordService executionRecordService;

    @GetMapping()
    public String record()
    {
        return prefix + "/record";
    }

    /**
     * 查询record列表
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ExecutionRecord executionRecord)
    {
        startPage();
        executionRecord.setCreateBy(ShiroUtils.getSysUser().getLoginName());
        List<ExecutionRecord> list = executionRecordService.selectExecutionRecordList(executionRecord);
        return getDataTable(list);
    }

    /**
     * 导出record列表
     */
    @Log(title = "record", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ExecutionRecord executionRecord)
    {
        executionRecord.setCreateBy(ShiroUtils.getSysUser().getLoginName());
        List<ExecutionRecord> list = executionRecordService.selectExecutionRecordList(executionRecord);
        ExcelUtil<ExecutionRecord> util = new ExcelUtil<ExecutionRecord>(ExecutionRecord.class);
        return util.exportExcel(list, "record数据");
    }

    /**
     * 新增record
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存record
     */
    @Log(title = "record", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ExecutionRecord executionRecord)
    {
        return toAjax(executionRecordService.insertExecutionRecord(executionRecord));
    }

    /**
     * 修改record
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        ExecutionRecord executionRecord = executionRecordService.selectExecutionRecordById(id);
        mmap.put("executionRecord", executionRecord);
        return prefix + "/edit";
    }

    /**
     * 修改保存record
     */
    @Log(title = "record", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ExecutionRecord executionRecord)
    {
        return toAjax(executionRecordService.updateExecutionRecord(executionRecord));
    }

    /**
     * 删除record
     */
    @Log(title = "record", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(executionRecordService.deleteExecutionRecordByIds(ids));
    }
}
